package com.webSite.demo.cy.downBook;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import cn.hutool.core.io.file.FileWriter;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.http.HtmlUtil;
import cn.hutool.http.HttpUtil;

public class Zuoshu {

	public static void main(String[] args) {
		String content = HttpUtil.get("https://www.ab74.com/96/96211/index.html",CharsetUtil.CHARSET_GBK);
		Document doc = Jsoup.parse(content);
		Elements links = doc.body().select(".dir_main_section li a");
		for (Element element : links) {
			getContent(getLink(element.attr("href")),element.text());
			System.out.println(element.text()+"完成");
		}
		
	}
	
	private static void getContent(String link, String name) {
		String content = HttpUtil.get(link,CharsetUtil.CHARSET_GBK);
		Document doc = Jsoup.parse(content);
		Element con = doc.body().getElementById("inner");
		
		FileWriter writer = new FileWriter("C:\\Users\\fengzihao\\Desktop\\二次元道士.txt");
		writer.append(HtmlUtil.cleanHtmlTag(con.toString()).replaceAll("&nbsp;", "").replaceAll("±杂∨志∨虫±", "").replace("http://www.tianxiabachang.cn/0_309/", "").replace("全能修炼至尊", ""));
	}

	/**
	 * 获取图片的名字
	* @Title: getImgName  
	* @Description: TODO()  
	* @param @param fileUrl
	* @param @return    参数  
	* @return String    返回类型  
	* @throws
	 */
	private static String getLink(String link) {
		StringBuilder builder = new StringBuilder("https://www.ab74.com");
		builder.append(link);
		return builder.toString();
	}
	
}
